//
//  BaseViewController.m
//  Alltelevisionnews
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
        
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    
    // 每个Conroller接收网络状态监控
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self selector:@selector(netStatusAction:) name:@"NotificationNetStatus" object:nil];
}


- (void)createNetStatusView:(NSString *)statusStr
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText = statusStr;
    hud.labelFont = [UIFont systemFontOfSize:14];
    hud.removeFromSuperViewOnHide = YES;
    [hud hide:YES afterDelay:1.5];
    hud.yOffset = (SCREEN_HEIGHT - 64) / 2.0 - 70;
}


- (void)netStatusAction:(NSNotification *)noti
{
    AFNetworkReachabilityStatus status = [noti.userInfo[@"netStatus"] integerValue];
    
    NSString *netStatusStr = nil;
    
    switch (status) {
        case AFNetworkReachabilityStatusReachableViaWiFi:
            NSLog(@"WiFi");
            netStatusStr = @"正在使用Wifi网络";
            break;
        case AFNetworkReachabilityStatusReachableViaWWAN:
            NSLog(@"手机网络");
            netStatusStr = @"正在使用2G/3G/4G网络";
            break;
        case AFNetworkReachabilityStatusNotReachable:
            NSLog(@"没有网络");
            netStatusStr = @"没有网络";
            break;
        case AFNetworkReachabilityStatusUnknown:
            NSLog(@"未知网络");
            netStatusStr = @"未知网络";
            break;
            
        default:
            break;
    }
    
    [self createNetStatusView:netStatusStr];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
